package com.ccys.cms.controller.masterData;

import com.ccys.cms.service.masterData.PharmacyService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.masterData.PharmacyDto;
import com.ccys.db.entity.TblPharmacyOperatingHours;
import com.ccys.db.vo.masterData.PharmacyGroupQueryByCountryIdVo;
import com.ccys.db.vo.masterData.PharmacyPageQueryVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @program: WhiteCoat
 * @description: 药房接口
 * @author: ZhangJingCan
 * @create: 2023-12-14 15:30
 **/
@RestController
@RequestMapping("masterData")
@Api(tags = "masterData-药房接口")
public class PharmacyController {

    @Autowired
    private PharmacyService pharmacyService;



    
    @PostMapping("pharmacy")
    @ApiOperation("保存药房")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id/修改必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "groupId", value = "groupId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "countryId", value = "countryId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "1:group;2:external;3:clinic", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pharmacyGroupId", value = "type=2时必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "clinicId", value = "type=3时必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "name", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "email", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "phone", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pharmacist", value = "pharmacist", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "dispOrder", value = "dispOrder", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "lattitude", value = "lattitude", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "longitude", value = "longitude", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "address", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "floorNumber", value = "floorNumber", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "postalCode", value = "postalCode", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "collectionInstruction", value = "0/1", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "collectionDay", value = "collectionInstruction为1的时候必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "importantNote", value = "importantNote", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "image", value = "image", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "hours", value = "药房营业时间对象List,如果用户填写完药房信息并没有点击保存，同时去操作药房营业时间并且添加了数据，当前并没有药房ID的时候点击提交，将数据放入这个集合",
                    required = false, dataType = "List", paramType = "List"),
    })
    public ResponseResult savePharmacy(@RequestBody PharmacyDto dto) {
        return pharmacyService.savePharmacy(dto);
    }


    @PutMapping("pharmacy")
    @ApiOperation("保存药房")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "对象id/修改必传", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "groupId", value = "groupId", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "countryId", value = "countryId", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "type", value = "1:group;2:external;3:clinic", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pharmacyGroupId", value = "type=2时必传", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "clinicId", value = "type=3时必传", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "name", value = "name", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "email", value = "email", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "phone", value = "phone", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pharmacist", value = "pharmacist", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "dispOrder", value = "dispOrder", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "lattitude", value = "lattitude", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "longitude", value = "longitude", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "address", value = "address", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "floorNumber", value = "floorNumber", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "postalCode", value = "postalCode", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "collectionInstruction", value = "0/1", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "collectionDay", value = "collectionInstruction为1的时候必传", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "importantNote", value = "importantNote", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "image", value = "image", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "hours", value = "药房营业时间对象List,如果用户填写完药房信息并没有点击保存，同时去操作药房营业时间并且添加了数据，当前并没有药房ID的时候点击提交，将数据放入这个集合",
            required = false, dataType = "List", paramType = "List"),
    })
    public ResponseResult edit(@RequestBody PharmacyDto dto) {
        return pharmacyService.savePharmacy(dto);
    }

    
    @DeleteMapping("pharmacy")
    @ApiOperation("根据ID删除药房")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult deletePharmacy(@ApiIgnore PharmacyDto dto) {
        return pharmacyService.deletePharmacy(dto);
    }

    
    @GetMapping("pharmacy")
    @ApiOperation("分页查询药房")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "groupId,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "clinicId", value = "clinicId,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "1:group;2:external;3:clinic,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pharmacyGroupId", value = "pharmacyGroupId,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "name,模糊查询", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "phone,模糊查询", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "code,页面显示：No,模糊查询", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "0/1,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "orderByStr",
                    value = "(默认传：t1.created_on descend),(左到右依次:t1.name,t5.name,t1.address,t1.disp_order,t1.status,t2.user_fullname,t1.created_on)",
                    required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<PageInfo<PharmacyPageQueryVo>, Object> findPagePharmacy(@ApiIgnore PharmacyDto dto) {
        return pharmacyService.findPagePharmacy(dto);
    }

    
    @GetMapping("pharmacy/pharmacyOperatingHours")
    @ApiOperation("根据药房ID查询药房营业时间集合数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "当前选中药房ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<List<TblPharmacyOperatingHours>, Object> findListPharmacyOperatingHours(@ApiIgnore PharmacyDto dto) {
        return pharmacyService.findListPharmacyOperatingHours(dto);
    }


    
    @PutMapping("pharmacy/status")
    @ApiOperation("根据ID修改药房状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态：0-禁用，1-启用", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updatePharmacyStatus(@ApiIgnore PharmacyDto dto) {
        return pharmacyService.updatePharmacyStatus(dto);
    }

    @PutMapping("pharmacy/updateDispOrder")
    @ApiOperation("根据ID修改药房状态")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "dispOrder", value = "序号值", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateDispOrder(@ApiIgnore PharmacyDto dto) {
        return pharmacyService.updateDispOrder(dto);
    }

    
    @GetMapping("pharmacy/pharmacyGroup")
    @ApiOperation("根据countryId查询制药集团集合(pharmacyGroup)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "countryId", value = "countryId", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<List<PharmacyGroupQueryByCountryIdVo>, Object> findListPharmacyGroupByCountryId(@ApiIgnore PharmacyDto dto) {
        return pharmacyService.findListPharmacyGroupByCountryId(dto);
    }


}
